<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/4/12
 * Time: 18:11
 */
use \Event as Event;
use \EventBase as EventBase;

$socket_address = "tcp://0.0.0.0:9001";

echo $socket_address.PHP_EOL;

$server = stream_socket_server($socket_address);

// 通过event监听 链接 的 读和写
$eventBase = new EventBase();
$event = new Event($eventBase, $server, Event::PERSIST | Event::READ | Event::WRITE, function($socket) use ($eventBase){
    echo '1hello event';

    $client = @stream_socket_accept($socket);

    $event2 = new Event($eventBase, $client , Event::PERSIST | Event::READ | Event::WRITE , function($socket){
        var_dump(fread($socket, 65535));

        fwrite($socket, 'test123123 ');

        fclose($socket);
    });

    $event2->add(0.1);

});

$event->add(0.1);
$eventBase->loop();